<?php

namespace App\Models;

use App\Events\ServiceOrderVerify;
use App\Traits\Model as ModelTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ServiceOrder extends Model
{
    use HasFactory;
    use ModelTrait;
    protected $table='service_order';

    public static $waitPay = 100;     // 待支付
    public static $payed   = 101;       // 已下单
    public static $cancel  = 200;      // 取消中
    public static $caceled = 201;     // 已取消

    public static $status = [
        100 => '待支付',
        101 => '已下单',
        200 => '取消中',
        201 => '已取消'
    ];

    protected $dispatchesEvents = [
        'saving' => ServiceOrderVerify::class,
        'saved' => ServiceOrderVerify::class,        // 更新后联动save
    ];

    public function setStartTimeAttribute($value){
        $this->attributes['start_time'] = strtotime($value);
    }

    public function setEndTimeAttribute($value){
        $this->attributes['end_time'] = strtotime($value);
    }

    public function getStartTimeAttribute($value){
        return date('Y-m-d H:i:s', $value);
    }

    public function getEndTimeAttribute($value){
        return date('Y-m-d H:i:s', $value);
    }
}
